﻿/// <Reference Name="MicrosoftAjax.js" />


(function () {


    function execute() {

        Type.registerNamespace('Toolkit');

        Toolkit.UI = function () {
            /// <summary>Toolkit.UI static class</summary>
            throw 'Static class does not have any instance';
        }

        Toolkit.UI.select = function (id) {
            /// <summary>Select form control based on id</summary>
            /// <param name="id" type="String" mayBeNull="false" optional="false">ID</param>
            var e = Function.validateParameters(arguments, [{ name: 'id', type: String, optional: false, mayBeNull: false }], true);
            if(e) throw e;

            return document.querySelector('input[id*="' + id + '"], select[id*="' + id + '"], textarea[id*="' + id + '"]');
        }

        Toolkit.UI.selectValue = function (id) {
            /// <summary>Select form control value based on id</summary>
            /// <param name="id" type="String" mayBeNull="false" optional="false">ID</param>
            /// <returns type="String"></returns>
            var e = Function.validateParameters(arguments, [{ name: 'id', type: String, optional: false, mayBeNull: false }], true);
            if (e) throw e;

            var ctl = Toolkit.UI.select(id);
            if (ctl === null) {
                return '';
            }

            switch (ctl.type) {
                case 'select-one':
                    return ctl.options[ctl.selectedIndex].value;
                    break;
                case 'text':
                    return ctl.value.trim();
                    break;
                case 'textarea':
                    return ctl.value.trim();
                    break;
                default:
                    return '';
            }

        }

        Toolkit.UI.registerClass('Toolkit.UI');
    }

    
    if (window.Sys && Sys.loader) {
        Sys.loader.registerScript('UI', null, execute);
    }
    else {
        execute();
    }


})();


